package crap;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class AxisComponent {
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JComponent axis = new JComponent() {
			Point2D origin = new Point2D.Double(20,20), destination = new Point2D.Double(-260,-260);
			double xArrow = 5, yArrow = 10;
			Path2D Axis = new Path2D.Double();
			{setAxis(20, 20, 260, 260);}
			public void setAxis(double originX, double originY, double w, double h) {
				this.origin.setLocation(originX, originY);
				this.destination.setLocation(originX+w, originY+h);
				Axis.moveTo(origin.getX(), origin.getY());
				Axis.lineTo(origin.getX(), destination.getY()-yArrow);
				Axis.lineTo(origin.getX()-xArrow/2., destination.getY()-yArrow);
				Axis.lineTo(origin.getX(), destination.getY());
				Axis.lineTo(origin.getX()+xArrow/2., destination.getY()-yArrow);
				Axis.lineTo(origin.getX(), destination.getY()-yArrow);
				Axis.moveTo(origin.getX(), origin.getY());

				Axis.lineTo(destination.getX()-yArrow, origin.getY());
				Axis.lineTo(destination.getX()-yArrow, origin.getY()-xArrow/2.);
				Axis.lineTo(destination.getX(), origin.getY());
				Axis.lineTo(destination.getX()-yArrow, origin.getY()+xArrow/2.);
				Axis.lineTo(destination.getX()-yArrow, origin.getY());
				Axis.moveTo(origin.getX(), origin.getY());
				Axis.closePath();
			}
			public void setArrow(double width, double height) {
				this.xArrow = width;
				this.yArrow = height;
			}
			@Override
			public void paint(Graphics g) {
				Graphics2D g2 = (Graphics2D)g;
		        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		        g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
		        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		        g2.setColor(Color.black);
		        
				g2.fill(this.Axis);
				g2.draw(this.Axis);
				super.paint(g);
			}
		};
		axis.setPreferredSize(new Dimension(300,300));
		
		frame.add(axis);
		frame.pack();
		frame.setVisible(true);
		
		
		
	}
}
